package com.net.xpay.operator;

import com.net.common.enums.base.StringEnum;
import com.net.xpay.core.CoreConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.reflections.Reflections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.util.Set;

/**
 * Created by  on 2017/12/16.
 */
@Slf4j
@SpringBootApplication
@EnableWebMvc
@Import({CoreConfiguration.class, WebConfiguration.class})
@ComponentScan(basePackages = {"com.net.xpay", "com.net.noah"})
public class OperatorWebMain {
    private static final Logger LOGGER = LoggerFactory.getLogger(OperatorWebMain.class);

    public static void main(String[] args) {
        checkStringEnum();

        SpringApplication.run(OperatorWebMain.class, args);
    }


    private static void checkStringEnum() {
        LOGGER.info("start to check string enum valid:");
        Set<Class<? extends StringEnum>> modules =
                new Reflections("com.net").getSubTypesOf(StringEnum.class);
        for (Class<? extends StringEnum> clazz : modules) {
            for (StringEnum e : clazz.getEnumConstants()) {
                if (!e.toString().toLowerCase().equals(e.getValue().toLowerCase())) {
                    LOGGER.error(e.toString() + "-" + e.getValue());
                }
            }
        }
    }

}
